package tool;

import cn.hutool.core.lang.Singleton;

import java.awt.*;
import java.awt.event.InputEvent;

/**
 * @author zhangpeiwen
 * @since 2020/10/1
 */
public class RobotTool {
    private static Robot robot = Singleton.get(Robot.class);

    public static void click(int x, int y){

        Point mouseInitPosition = MouseInfo.getPointerInfo().getLocation();
        int mask = InputEvent.BUTTON1_MASK;
        robot.mouseMove(x, y);
        try{
            // wait 100ms to avoid the robot action out of order
            Thread.sleep(200);
        }
        catch (InterruptedException e){
            e.printStackTrace();
        }
        robot.mousePress(mask);
        robot.mouseRelease(mask);
        robot.mousePress(mask);
        robot.mouseRelease(mask);
        robot.mouseMove((int)mouseInitPosition.getX(), (int)mouseInitPosition.getY());
    }
}
